<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - svg loader</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
		body {
			color: #ffffff;
			font-family: Monospace;
			font-size: 13px;
			text-align: center;
			font-weight: bold;
			background-color: #000000;
			margin: 0px;
			overflow: hidden;
		}

		#info {
			position: absolute;
			top: 0px;
			width: 100%;
			padding: 5px;
		}

		a {
			color: #ffffff;
		}
		</style>
	</head>

	<body>

		<div id="container"></div>

		<script type="text/javascript" src="../../build/three.min.js"></script>
		<script src="../../examples/js/controls/OrbitControls.js"></script>
		<script src="../../examples/js/loaders/SVGLoader.js"></script>
		<script src="../../examples/js/libs/stats.min.js"></script>

		<script>

			var renderer, stats, scene, camera;

			init();
			animate();

			//

			function init() {

				var container = document.getElementById( 'container' );

				//

				scene = new THREE.Scene();
				scene.background = new THREE.Color( 0xb0b0b0 );

				//

				camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
				camera.position.set( 0, 0, 200 );

				//

				var helper = new THREE.GridHelper( 160, 10 );
				helper.rotation.x = Math.PI / 2;
				scene.add( helper );

				//

				var loader = new THREE.SVGLoader();
				loader.load( './tiger.svg', function ( paths ) {

					var group = new THREE.Group();
					group.scale.multiplyScalar( 0.25 );
					group.position.x = - 70;
					group.position.y = 70;
					group.scale.y *= - 1;

					for ( var i = 0; i < paths.length; i ++ ) {

						var path = paths[ i ];

						var material = new THREE.MeshBasicMaterial( {
							color: path.color,
							side: THREE.DoubleSide,
							depthWrite: false
						} );

						var shapes = path.toShapes( true );

						for ( var j = 0; j < shapes.length; j ++ ) {

							var shape = shapes[ j ];

                            var geometry = new THREE.ShapeBufferGeometry( shape );
                            var solid = new THREE.ExtrudeBufferGeometry(shape , {depth:20});

                            var geometryMesh = new THREE.Mesh(geometry, material);
                            var solidMesh = new THREE.Mesh( solid, material );
                            
                            solidMesh.position.set(800,0,0);
                            solidMesh.rotation.y = 0.1*Math.PI;

							group.add( geometryMesh );
							group.add( solidMesh );

						}

					}

					scene.add( group );

				} );

				//

				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );

				//

				var controls = new THREE.OrbitControls( camera, renderer.domElement );
				controls.screenSpacePanning = true;

				//

				stats = new Stats();
				container.appendChild( stats.dom );

				//

				window.addEventListener( 'resize', onWindowResize, false );

				document.body.addEventListener( 'dblclick', function ( event ) {

					var group = scene.children[ 1 ];
					group.traverse( function ( child ) {

						if ( child.material ) child.material.wireframe = ! child.material.wireframe;

					} );

				} );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			function render() {

				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>
